package com.qfedu.mtl.service.impl;

import com.qfedu.mtl.dao.UserDao;
import com.qfedu.mtl.dao.impl.UserDaoImpl;
import com.qfedu.mtl.entity.User;
import com.qfedu.mtl.service.UserService;
import com.qfedu.mtl.util.page.Pager;

import java.util.List;

/**
 * @version v1.0
 * @Date 2023/9/26 20:34
 * @Author Kyi
 * @Email zywKyi@163.com
 */
public class UserServiceImpl implements UserService {
    UserDao userDao = new UserDaoImpl();

    @Override
    public void add(User user) {
        userDao.save(user);

    }

    @Override
    public void delete(Integer id) {
        userDao.remove(id);
    }

    @Override
    public void update(User user) {
        userDao.update(user);

    }

    @Override
    public User findById(Integer id) {
        User user = userDao.selectById(id);

        return user;
    }

    @Override
    public Pager findAllPage(Integer pageNum, Integer pageSize, String username) {
//        查询所有用户

        List<User> userList = userDao.selectAll(pageNum, pageSize, username);

        //查询所有条数
        Integer total = userDao.selectAllTotal(username);
        Pager pager = new Pager(userList, pageNum, pageSize, total);
        return pager;
    }
}
